﻿var aesAuthor = {
    isOk: false,
    login: async function () {
        var res = await lg.requestAsync({
            url: "/base/getrsakey",
            method: "post"
        });
        if (res.code == 0) {
            var key = lg.GetSN(16);
            localStorage.aesParam = JSON.stringify({ rid: res.data.rid, aesKey: key });
            var cipher = new lg.rsa({
                pubKey: res.data.rsaKey,
                txt: key
            }).encrypt();
            this.isOk = true;
            console.log(cipher);
            this.encrypt("12312321");
            return true;
        }
        return false;
    },
    getKey:function () {

    },
    postKey: async function (key) {
        var res = await lg.requestAsync({
            url: "/base/getrsakey",
            method: "post"
        });
    },
    encrypt: function (data) {
        if (typeof (data) == "object") {
            data = JSON.stringify(data);
        }
        var _key = CryptoJS.enc.Utf8.parse("KW4pBf3OmBlcUwmB");
        var _data = CryptoJS.enc.Utf8.parse(data);
        var cipher = CryptoJS.AES.encrypt(_data, _key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        })
        var base64Str = cipher.ciphertext.toString(CryptoJS.enc.Base64);
        console.log(base64Str)
    }
}
aesAuthor.login();
//export { aesAuthor }